<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="billNo">
        <el-input
          v-model="queryParams.billNo"
          placeholder="请输入单据编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据日期" prop="billTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.billTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择单据日期">
        </el-date-picker>
      </el-form-item>
      <template v-if="toggleSearchStatus">
        <el-form-item label="往来单位" prop="organId">
          <el-select
            v-model="queryParams.organId"
            placeholder="请选择往来单位"
            clearable
            filterable
            size="small"
            @keyup.enter.native="handleQuery"
          >
            <el-option
              v-for="supplier in suppliers"
              :key="supplier.id"
              :label="`${supplier.supplier}[${supplier.type}]`"
              :value="supplier.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      <el-form-item label="财务人员" prop="handsPersonId">
        <el-select  v-model="queryParams.handsPersonId" placeholder="请选择财务人员"  @keyup.enter.native="handleQuery">
            <el-option
              v-for="person in persons"
              :key="person.id"
              :label="person.name"
              :value="person.id">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="操作员" prop="creator">
        <el-select
          v-model="queryParams.creator"
          placeholder="请选择操作员"
          clearable
          size="small"
        >
          <el-option
            v-for="user in users"
            :key="user.userId"
            :label="user.nickName"
            :value="user.userId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      </template>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="text" size="small" style="margin-left: 8px" @click="handleToggleSearch" >{{ toggleSearchStatus ? '收起' : '展开' }}<i v-if="toggleSearchStatus" class="el-icon-arrow-up"></i><i v-else-if="!toggleSearchStatus" class="el-icon-arrow-down"></i></el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['basicsystem:accountheadqcyf:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['basicsystem:accountheadqcyf:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-dropdown @command="handleCommand">
          <el-button :disabled="multiple" size="small" type="danger">
            批量操作<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="delete" v-hasPermi="['basicsystem:accountheadqcyf:remove']"><i class="el-icon-delete"></i>删除</el-dropdown-item>
            <el-dropdown-item command="enabled" v-hasPermi="['basicsystem:accountheadqcyf:check']" ><i class="el-icon-document-checked"></i>审核</el-dropdown-item>
            <el-dropdown-item command="disabled" v-hasPermi="['basicsystem:accountheadqcyf:unCheck']"><i class="el-icon-document-delete"></i>反审核</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading"  max-height="620px" :data="accountheadList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" v-if="false" />
      <el-table-column label="往来单位" align="center" prop="organId" :formatter="organFormat"/>
      <el-table-column label="财务人员" align="center" prop="handsPersonId" :formatter="personFormat"/>
      <el-table-column label="单据编号" align="center" prop="billNo" />
      <el-table-column label="单据日期" align="center" prop="billTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.billTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作员" align="center" prop="creator" :formatter="creatorFormat"/>
      <el-table-column label="合计金额" align="center" prop="totalPrice" />
      <el-table-column label="付款金额" align="center" prop="totalPrice" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.account_head_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['basicsystem:accountheadqcyf:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.status ==0"
            v-hasPermi="['basicsystem:accountheadqcyf:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="scope.row.status ==0"
            v-hasPermi="['basicsystem:accountheadqcyf:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改财务主对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1300px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="往来单位" prop="organId">
              <el-select
                v-model="form.organId"
                placeholder="请选择往来单位"
                clearable
                filterable
                size="small"
                @change="organSelectChange"
              >
                <el-option
                  v-for="supplier in suppliers"
                  :key="supplier.id"
                  :label="`${supplier.supplier}[${supplier.type}]`"
                  :value="supplier.id"
                >
                </el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="财务人员" prop="handsPersonId">
              <el-select  v-model="form.handsPersonId" clearable filterable placeholder="请选择财务人员"
                ref="personSelect" @visible-change="v => visibleChange(v,'personSelect', addPersonClick, '新增经手人')">
                  <el-option
                    v-for="person in persons"
                    :key="person.id"
                    :label="person.name"
                    :value="person.id">
                  </el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="单据日期" prop="billTime">
              <el-date-picker clearable size="small"
                v-model="form.billTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择单据日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="单据编号" prop="billNo">
              <el-input v-model="form.billNo" placeholder="请输入单据编号" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col >
<!--            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="small" @click="handleAddZnAccountItem">添加</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" :disabled="item.multiple" icon="el-icon-delete" size="small" @click="handleDeleteZnAccountItem">删除</el-button>
              </el-col>
            </el-row> -->
            <el-table :data="znAccountItemList" :row-class-name="rowZnAccountItemIndex" @selection-change="handleZnAccountItemSelectionChange" ref="znDepotItem" show-summary :summary-method="getItemSummaries" size="small" :max-height="380">
              <!-- <el-table-column label="序号" align="center" prop="index" width="50" /> -->
              <el-table-column type="selection" width="50" align="center" class-name="allowDrag"/>
              <el-table-column label="期初应付金额" prop="eachAmount" width="100">
                <template slot-scope="scope">
                  <!-- <el-input size="small" v-model="scope.row.eachAmount" type="number"/> -->
                  <el-input-number style="width: 100%;" :precision="2" :min="0" :controls="false" v-model="scope.row.eachAmount"></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="备注" prop="remark" width="450">
                <template slot-scope="scope">
                  <el-input size="small" v-model="scope.row.remark" />
                </template>
              </el-table-column>
            </el-table>
            <el-row style="top: 0.625rem;">
              <el-form-item label="备注" prop="remark" >
                <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
              </el-form-item>
            </el-row>
            <el-row>
              <el-col :span="6">
                  <el-form-item label="付款账户" prop="accountId" >
                    <el-select
                      v-model="form.accountId"
                      placeholder="请选择付款账户"
                      clearable
                      ref="accountSelect"
                      @visible-change="v => visibleChange(v,'accountSelect', addAccountClick, '新增结算账户')"
                    >
                      <el-option
                        v-for="account in accounts"
                        :key="account.id"
                        :label="account.name"
                        :value="account.id"
                      >
                        <span style="float: left" class="span-style">{{ account.name }}</span>
                        <div class="flag" style="float: left;">
                          <svg-icon icon="edit" iconClass="template_edit_style" />
                        </div>
                      </el-option>
                    </el-select>
                  </el-form-item>
              </el-col>
              <el-col :span="6">
                   <el-form-item label="合计金额" prop="totalPrice">
                     <el-input-number placeholder="请输入合计金额" disabled :precision="2"  style="width: 100%;" :min="0" :controls="false" v-model="form.totalPrice"></el-input-number>
                   </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="付款金额" prop="changeAmount">
                  <el-input-number placeholder="请输入付款金额" disabled :precision="2"  style="width: 100%;" :min="0" :controls="false" v-model="form.changeAmount"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="6">
              </el-col>
              <el-col :span="6">
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="附件名称" prop="fileName" label-width="100px">
                <fileUpload v-model="form.fileName" :fileType="['png', 'jpg', 'jpeg','xls','doc','pdf']"/>
              </el-form-item>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改经手人对话框 -->
    <el-dialog :title="person.title" :visible.sync="person.open" width="500px" append-to-body>
      <el-form ref="personForm" :model="person.form" :rules="person.rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="person.form.name" placeholder="请输入姓名" style="width: 80%;"/>
        </el-form-item>
         <el-form-item label="类型" prop="type">
          <el-select v-model="person.form.type" placeholder="请选择类型" size="small" disabled  style="width: 80%;">
            <el-option
              v-for="dict in dict.type.person_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
         </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPersonForm">确 定</el-button>
        <el-button @click="cancelPerson">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改结算账号对话框 -->
    <el-dialog :title="account.title" :visible.sync="account.open" width="600px" append-to-body>
      <el-form ref="accountForm" :model="account.form" :rules="account.rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="account.form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="编号" prop="serialNo">
          <el-input v-model="account.form.serialNo" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="期初金额" prop="initialAmount">
          <el-input v-model="account.form.initialAmount" placeholder="请输入期初金额" />
        </el-form-item>
        <el-form-item label="当前余额" prop="currentAmount">
          <el-input v-model="account.form.currentAmount" placeholder="请输入当前余额" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="account.form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAccountForm">确 定</el-button>
        <el-button @click="cancelAccount">取 消</el-button>
      </div>
    </el-dialog>

    <bill-detail ref="billDetail"></bill-detail>
  </div>
</template>

<script>
import { listAccounthead, getAccounthead, delAccounthead,delAccountheadQc, addAccounthead, updateAccounthead, updateAccountheadStatus,getAccountDetailByNumber } from "@/api/basicsystem/accounthead";
import {  addPerson } from "@/api/basicsystem/person";
import {parseTime} from "@/utils/ruoyi";
import BillDetail from '../comm/dialog/BillDetail';
import * as math from 'mathjs'
export default {
  name: "Accounthead",
  dicts: ['account_head_status','person_type'],
  components: { BillDetail },
  data() {
    return {
      // 搜索栏 展开/收起 按钮
      toggleSearchStatus:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 财务主表格数据
      accountheadList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: '期初应付',
        organId: null,
        handsPersonId: null,
        creator: null,
        changeAmount: null,
        discountMoney: null,
        totalPrice: null,
        accountId: null,
        billNo: null,
        billTime: null,
        fileName: null,
        status: null,
        tenantId: null,
        deleteFlag: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        handsPersonId:[
          { required: true, message: "财务人员不能为空", trigger: "blur" }
        ],
        billTime:[
          { required: true, message: "单据日期不能为空", trigger: "blur" }
        ],
        accountId:[
          { required: true, message: "付款账户不能为空", trigger: "blur" }
        ],
        totalPrice:[
          { required: true, message: "收入金额不能为空", trigger: "blur" }
        ],
      },
      // 单据子表格数据
      znAccountItemList: [],
      //选中单据子表数据
      checkedZnAccountItem:[],
      //单据子表操作
      item:{
        // 非多个禁用
        multiple: true,
        // 表单参数
        form: {},
      },
      //供应商、客户
      suppliers:[],

      suppliers1:[],
      // 操作员
      users:[],
      //财务人员下拉框数据
      persons:[],
      //账户下拉框数据
      accounts:[],
      //默认账户
      defaultAcount:null,
      //新增账户窗口
      account:{
        // 弹出层标题
        title: "新增账户",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
         name :[
           { required: true, message: "名称不能为空", trigger: "blur" }
         ],
         serialNo :[
           { required: true, message: "编码不能为空", trigger: "blur" }
         ],
        },
      },
      //新增经手人
      person:{
        open:false,
        title:"新增经手人",
        form:{},
        rules:{
          name:[
             { required: true, message: "名称不能为空", trigger: "blur" }
          ],
          type:[
             { required: true, message: "类型不能为空", trigger: "blur" }
          ],
        }
      }
    };
  },
  watch:{
    'form.totalPrice':function(n,o){
      this.form.changeAmount = this.form.totalPrice;
    },
  },
  beforeCreate() {
    this.getSuppliers({params :{'type':'会员','qcyf':1}}).then(response => {
      // console.log(response.data)
      this.suppliers = response.data;
    });
    this.getSuppliers({params :{'type':'会员'}}).then(response => {
      // console.log(response.data)
      this.suppliers1 = response.data;
    });
    this.getUsers().then(response => {
      this.users =  response.data;
    });
  },
  created() {
    this.getList();
  },
  mounted() {
    /** 查询经手人列表 */
    this.getPersons({'type':'财务员'}).then(response =>{
      this.persons =  response.data;
      });
      this.getAccounts().then(response =>{
        this.accounts =  response.data;
        this.defaultAcount = this.accounts.find(item => item.isDefault==1)
      });
  },
  methods: {
    organSelectChange(){
      // this.znAccountItemList =[];
      let organId = this.form.organId ;
      if(organId !=null && organId != undefined && organId != ""){//做限制
        // let tempOrgan = this.suppliers.find(item =>  item.id == organId);
        // this.znAccountItemList[0].
      }else{
        this.znAccountItemList[0].eachAmount = 0;
      }
    },
    //根据单据查询详情
    handleDetail(row){
        let that = this
        let queryParm={ billNo: row.billNo }
        getAccountDetailByNumber(queryParm).then(response => {
          that.$refs.billDetail.show(response.data,row.type);
          that.$refs.billDetail.title=row.type +"-详情";
        });
    },
    //会员id转为名称
    organFormat(row, column) {
      var actions = [];
      if(row !=null){
        this.suppliers1.filter(item => {
        	if (item.id == row.organId) {
        		actions.push(item.supplier);
        	}
        })
      }
      return actions.join('');
    },
    //操作员id转为名称
    creatorFormat(row, column) {
      var actions = [];
      if(row !=null){
        this.users.filter(item => {
          if (item.userId == row.creator) {
            actions.push(item.nickName);
          }
        })
      }
      return actions.join('');
    },
    //操作员id转为名称
    personFormat(row, column) {
      var actions = [];
      if(row !=null){
        this.persons.filter(item => {
        	if (item.id == row.handsPersonId) {
        		actions.push(item.name);
        	}
        })
      }
      return actions.join('');
    },
    /** 查询财务主列表 */
    getList() {
      this.loading = true;
      listAccounthead(this.queryParams).then(response => {
        this.accountheadList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: '期初应付',
        organId: null,
        handsPersonId: null,
        creator: null,
        changeAmount: null,
        discountMoney: null,
        totalPrice: 0,
        accountId: null,
        billNo: null,
        billTime: null,
        remark: null,
        fileName: null,
        status: "0",
        tenantId: null,
        deleteFlag: null
      };
      this.znAccountItemList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.handleAddZnAccountItem();
      this.open = true;
      this.title = "新增";
      this.getAccountNo('QCYF').then(response =>{
         this.form.billNo = response.data;
      });
      this.form.billTime =  parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}');
      if(this.defaultAcount){
        this.form.accountId= this.defaultAcount.id;
      }
      // this.$nextTick(()=>{
      //   //此时能够调到ref，而且table也正常刷新了
      //   const el = this.$refs.znDepotItem.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0];
      //   const that = this;
      //   const sortable = Sortable.create(el, {
      //         handle: ".allowDrag",
      //         onEnd: evt => {
      //           const targetRow = this.znDepotItemList.splice(evt.oldIndex, 1)[0];
      //           this.znDepotItemList.splice(evt.newIndex, 0, targetRow);
      //           for (let index in this.znDepotItemList) {
      //             this.znDepotItemList[index].sort = parseInt(index) + 1;
      //           }
      //           // console.log(this.znDepotItemList)
      //         }
      //   });
      // });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAccounthead(id).then(response => {
        this.form = response.data;
        this.znAccountItemList = response.data.znAccountItemList;
        this.open = true;
        this.title = "编辑";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.znAccountItemList = this.znAccountItemList;
          if(this.znAccountItemList.length==0){
            this.$modal.msgError("单据明细不能为空");
          }else{
            if (this.form.id != null) {
              updateAccounthead(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addAccounthead(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }

        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除财务主编号为"' + ids + '"的数据项？').then(function() {
        return delAccountheadQc(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basicsystem/accounthead/export', {
        ...this.queryParams
      }, `期初应付_${new Date().getTime()}.xlsx`)
    },
    /** 搜索栏展开/收起按钮操作 */
    handleToggleSearch(){
      this.toggleSearchStatus = !this.toggleSearchStatus;
    },
    /** 批量操作按钮操作 */
    handleCommand(command) {
      if(command == 'delete'){
        // this.$message('click on item ' + command);
        this.handleDelete(this);
      }else if(command == 'enabled'){
         this.handleStatus(1);
        // this.$message('click on item ' + command);
      }else if(command == 'disabled'){
        this.handleStatus(0);
        // this.$message('click on item ' + command);
      }else if(command == 'batchSetDepot'){
        this.handleDepot(0);
      }else if(command == 'goAddDepot'){
        this.handleDepot(1);
      }
    },
    /** 审核、反审核按钮操作 */
    handleStatus(status) {
      const statusTxt = status == 1 ? "审核":"反审核";
      const ids = this.ids;
      this.$modal.confirm('是否确认'+statusTxt+' 编号为"' + ids + '"的单据？').then(function() {
        return updateAccountheadStatus(ids,status);
     }).then((res) => {
		this.getList();
		if(res.code == 200){
			this.$modal.msgSuccess(res.msg);
		}else{
			this.$modal.msgError(res.msg);
		}
      }).catch(() => {});
    },
    /** 单据子序号 */
      rowZnAccountItemIndex({ row, rowIndex }) {
        row.index = rowIndex + 1;
      },
      /** 复选框选中数据 */
      handleZnAccountItemSelectionChange(selection) {
        this.checkedZnAccountItem = selection.map(item => item.index)
        this.item.multiple = !selection.length
      },
    /** 单据子添加按钮操作 */
    handleAddZnAccountItem() {
      let obj = {};
      obj.headerId = "";
      obj.accountId = "";
      obj.inOutItemId = "";
      obj.billId = "";
      obj.needDebt   = '';
      obj.finishDebt = "";
      obj.eachAmount = 0;
      this.znAccountItemList.push(obj);
    },
    /** 单据子删除按钮操作 */
    handleDeleteZnAccountItem() {
      if (this.checkedZnAccountItem.length == 0) {
        this.$modal.msgError("请先选择要删除的单据子数据");
      } else {
        const znAccountItemList = this.znAccountItemList;
        const checkedZnAccountItem = this.checkedZnAccountItem;
        this.znAccountItemList = znAccountItemList.filter(function(item) {
          return checkedZnAccountItem.indexOf(item.index) == -1
        });
      }
    },
    //新增页面 商品列表合计
    getItemSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        const that = this;
        columns.forEach((column, index) => {
          if(column.property =='eachAmount'){
            const values = data.map(item => Number(item[column.property]));
            if (!values.every(value => isNaN(value))) {
              sums[index] = values.reduce((prev, curr) => {
                const value = Number(curr);
                if (!isNaN(value)) {
                    return math.add(math.bignumber(prev),math.bignumber(curr));
                } else {
                    return math.bignumber(prev);
                }
              }, 0);
            }
             sums[index] = (sums[index] !=undefined && sums[index] !=null ?parseFloat(sums[index]):0);
            // console.log(sums[index],parseFloat(sums[index]),math.bignumber(sums[index]))
              this.form.totalPrice = sums[index];
              return;
          }else{
            sums[index] = '';
             return;
          }
        });
        return sums;
      },
    visibleChange(visible, refName, onClick, btnName) {
        if (visible) {
          const ref = this.$refs[refName]
          let popper = ref.$refs.popper
          if (popper.$el) popper = popper.$el
          if (!Array.from(popper.children).some(v => v.className === 'el-template-menu__list')) {
              const el = document.createElement('ul')
              el.className = 'el-template-menu__list'
              el.style = 'border-top:2px solid rgb(219 225 241); font-size: 14px;margin-top: 0px;margin-bottom: 3px;'
              el.innerHTML = `<li class="el-cascader-node el-select-dropdown__item" style="margin-left: -40px;height:37px;line-height: 50px">
                      <span class="el-cascader-node__label" style="margin-left: -13px ;"><i class="font-blue el-icon-plus" style="padding-right: 3px;"></i>`+btnName+`</span>
                      </li>`
              popper.appendChild(el)
              el.onclick = () => {
                // 底部按钮的点击事件 点击后想触发的逻辑也可以直接写在这
                onClick && onClick()
                if (ref.toggleDropDownVisible) {
                     ref.toggleDropDownVisible(false)
                } else {
                     ref.visible = false
                }
              }
          }
        }
    },
    /**
     * 点击添加经手人
     */
    addPersonClick(){
      this.resetPerson();
      this.person.open =  true;
    },
    /** 新增会员提交按钮 */
    submitPersonForm() {
      this.$refs["personForm"].validate(valid => {
        if (valid) {
            addPerson(this.person.form).then(response => {
              this.$modal.msgSuccess("经手人新增成功");
              this.person.open = false;
              this.getPersons({'type':'财务员'}).then(response => {
               this.persons = response.data;
             });
            });
        }
      });
    },

    cancelPerson(){
      this.person.open = false;
    },
    // 新增会员表单重置
    resetPerson() {
      this.person.form = {
       id: null,
       type: '财务员',
       name: null,
       tenantId: null,
       deleteFlag: null
      };
      this.resetForm("personForm");
    },
    /**
     * 点击添加账户
     */
    addAccountClick(){
      this.resetAccount();
      this.account.open =  true;
    },
    /** 新增账户提交按钮 */
    submitAccountForm() {
      this.$refs["accountForm"].validate(valid => {
        if (valid) {
            addAccount(this.account.form).then(response => {
              this.$modal.msgSuccess("账户新增成功");
              this.account.open = false;
              this.getAccounts().then(response => {
               this.accounts = response.data;
             });
            });
        }
      });
    },
    cancelAccount(){
      this.account.open = false;
      this.resetAccount();
    },
    // 表单重置
    resetAccount() {
      this.account.form = {
        id: null,
        name: null,
        serialNo: null,
        initialAmount: null,
        currentAmount: null,
        remark: null,
        isDefault: null,
        tenantId: null,
        deleteFlag: null
      };
      this.resetForm("accountForm");
    },
  }
};
</script>
<style>
  .el-dialog__body > .el-form > .el-row > div.el-col > div.el-table > .el-table__body-wrapper > table > tbody > .el-table__row > .el-table__cell > .cell{
    padding-left: 1px;
    padding-right: 1px;
  }
  .el-dialog__body > .el-form > .el-row > div.el-col > div.el-table > .el-table__body-wrapper > table > tbody > .el-table__row > .el-table__cell > .cell > .el-input > .el-input__inner{
    padding: 0 2px;
  }
  .el-dialog__body > .el-form > .el-row > div.el-col > div.el-table > .el-table__body-wrapper > table > tbody > .el-table__row > .el-table__cell > .cell > .el-form-item > .el-form-item__content > .el-input-number > .el-input > .el-input__inner {
      padding-left: 0px;
      padding-right: 0px;
  }
  .el-dialog__body > .el-form > .el-row > div.el-col > div.el-table > .el-table__body-wrapper > table > tbody > .el-table__row > .el-table__cell > .cell > .dashed > .el-input__inner{
     border: 1px dashed #DCDFE6;
  }
  .el-dialog__wrapper > .el-dialog > .el-dialog__body > .el-form > .el-row > .el-col-8 .el-form-item > label.el-form-item__label{
        font-size: 18px;
        font-weight: bolder;
        /* width: 150px; */
  }
 /* .el-dialog__wrapper > .el-dialog > .el-dialog__body > .el-form > .el-row > .el-col-8 .el-form-item > div.el-form-item__content{
    margin-left: 150px;
  } */
  .el-dialog__wrapper > .el-dialog > .el-dialog__body > .el-form > .el-row > .el-col-8 .el-form-item > .el-form-item__content > .totalClass > input{
        border-left-width: 0!important;
        border-top-width: 0!important;
        border-right-width: 0!important;
        text-align: center;
        font-size: 28px;
        font-weight: bolder;

  }
  .el-dialog__wrapper > .el-dialog > .el-dialog__body > .el-form > .el-row > .el-col-8 .el-form-item > .el-form-item__content > .totalClass1 > input{
    color: purple;
  }
  .el-dialog__wrapper > .el-dialog > .el-dialog__body > .el-form > .el-row > .el-col-8 .el-form-item > .el-form-item__content > .totalClass2 > input{
    color: red;
  }
  .el-dialog__wrapper > .el-dialog > .el-dialog__body > .el-form > .el-row > .el-col-8 .el-form-item > .el-form-item__content > .totalClass3 > input{
    color: green;
  }
  .el-dialog__wrapper > .el-dialog > .el-dialog__body > .el-form > .el-row > .el-col-8 .el-form-item > .el-form-item__content > .totalClass > input.el-input__inner:hover{
     border-color: #0055ff;
  }
</style>
